package com.by.controller;

import com.by.bean.User;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "用户管理")
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    @ApiOperation("保存用户")
    @PostMapping("/user")
    public ResultBean save(@RequestBody User user) {
        int rs = userService.saveEntity(user);
        return saveResult(rs);
    }

    @ApiOperation("修改用户")
    @PutMapping("/user")
    public ResultBean update(@RequestBody User user) {
        int rs = userService.updateEntity(user);
        return updateResult(rs);
    }


    @ApiOperation("删除用户")
    @DeleteMapping("/user")
    public ResultBean delete(int id){
        int rs=userService.deleteEntity(id);
        return deleteResult(rs);
    }
}
